﻿var weightForDistrictCLCInfoList;

function zzzWeightForDistrict() {
    if (Ext.getCmp('app-dunCount-panel') == null) {
        mapPanel.add(new Ext.Panel({

            region: 'center',
            id: 'app-dunCount-panel',
            title: '中转站按区统计',
            anchor: '100% 100%',
            closable: true,
            autoScroll: true,
            containerScroll: true,
            //margins: '0 0 0 5',
            border: false,
            iconCls: 'nav',
            items: [createConditionsDun(), {
                layout: 'fit',
                items: [createDunCountResult()]
            }]
        }));
    }
    mapPanel.setActiveTab('app-dunCount-panel');

    updataData(dataFormat(new Date(), "yyyy-MM-dd"), "");
}


function updataData(dataPara, typePara) {
    weightForDistrictCLCInfoList.removeAll();
    weightForDistrictCLCInfoList.load({
        params: { dateString: dataPara, type: "中转站", typeLJ: typePara, op: 'GetDistrictWeightAllBh' }
                    , callback: function (records, options, success) {
                        document.getElementById('ljSearchData').innerHTML = records[0].get("dateAll");
                        document.getElementById('ljSearchRepo').innerHTML = records[0].get("weightAll");
                    }
    });
    
}

function createConditionsDun() {
    return new Ext.Panel({
        labelAlign: 'top',
        frame: true,
        bodyStyle: 'padding:0px 0px 0',
        items: [{
            //                                    columnWidth: .5,
            height: 25,
            layout: { type: 'hbox' },
            items: [
                                    {
                                        xtype: "label",
                                        id: "ljSearchData",
                                        width: 300,
                                        text: '查询日期：2020-03-02 至 2020-05-05'
                                    }, {
                                        width: 100,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "今日",
                                        id: "date1",
                                        checked: true

                                    }, {
                                        width: 100,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "昨日",
                                        id: "date2"

                                    }]
        },

                                {
                                    //                                    columnWidth: .5,
                                    height: 25,
                                    layout: { type: 'hbox' },
                                    items: [
                                    {
                                        xtype: "label",
                                        id: "ljSearchRepo",
                                        width: 300,
                                        text: '查询结果：2000000吨'
                                    }, {
                                        xtype: "label",
                                        width: 70,
                                        text: '垃圾类型：'
                                    },
                                    initTYPELJ()]

                                }],
        buttonAlign: 'center',
        buttons: [{
            text: "查询",
            name: "button",
            handler: function () {
                var dunDate;
                if (Ext.getCmp('date1').checked) {
                    var yesterday = new Date();
                    dunDate = dataFormat(yesterday, "yyyy-MM-dd");
                }
                if (Ext.getCmp('date2').checked) {
                    var yesterday = new Date();
                    yesterday.setTime(yesterday.getTime() - 3600 * 1000 * 24);
                    dunDate = dataFormat(yesterday, "yyyy-MM-dd");
                }
                if (Ext.getCmp('date3').checked) {
                    if (Ext.getCmp('dateSearch').getValue() == "") {
                        Ext.MessageBox.alert("提示", "请选择日期");
                    } else {
                        dunDate = dataFormat(Ext.getCmp('dateSearch').getValue(), "yyyy-MM-dd");
                    }
                }
                if (Ext.getCmp('date4').checked) {
                    if (Ext.getCmp('monthSearch').getValue() == "") {
                        Ext.MessageBox.alert("提示", "请选择月份");
                    } else {
                        dunDate = dataFormat(Ext.getCmp('monthSearch').getValue(), "yyyy-MM"); ;
                    }

                }
                updataData(dunDate, Ext.get('cmbTypeLJ').getValue(), "中转站");
            }
        }]
    });
}

function getVehicleWeight(clientName, name) {
    tabPanel = new Ext.TabPanel({

        fullscreen: true,
        activeTab: 0,
        defaults: {
            styleHtmlContent: true
        },
        items: [
            {
                title: '全部',
                html: '<iframe src="./html/WeightVehicle.aspx?clientName=' + clientName + '&dateString=' + document.getElementById("ljSearchData").value + '&name=' + name + ' "width="100%" height="100%"></iframe>'
            }
            ]
    });

    var window = new Ext.Window({
        title: userName,
        layout: 'fit',       //弹出窗口内布局会充满整个窗口;
        width: 500,          //设置窗口大小;
        height: 300,
        items: tabPanel         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
    });
    window.show();
}
function rMenu2Fn(bb) {
    alert(bb);
}
function createDunCountResult() {
    //    var sm = new Ext.grid.CheckboxSelectionModel();

    if (SelectTypeDUNCOUNT == "2") { 
    } else { 
    }
    var cm = new Ext.grid.ColumnModel([
        { header: '地区', dataIndex: 'name', sortable: true, width: 60 },
    //        { header: '报警类型', dataIndex: 'Alarm_Type', sortable: true, renderer: GetAlarmTypeString, width: 64 },
        {header: '吨数', dataIndex: 'dunCount', sortable: true, width: 58 },
        {
            header: "操作",
            width: 150,
            dataIndex: 'operation',
            align: 'center',
            renderer: function (record, rowIndex) {
                return "<button type='button' onclick='rMenu1Fn(" + store + "," + rowIndex + ")'>中转站详情</button>"
                    + "<button type='button' onclick='getVehicleWeight('aa')'>车辆详情</button>";
            }
        }]);

    // 数据源
    dunCountInfoList = new Ext.data.Store({
        url: "../Json/JsonGetWeightInfoList.ashx",
        reader: new Ext.data.JsonReader(
                { root: 'data' },
                Ext.data.Record.create([{ name: 'name' }, { name: 'dunCount' }, { name: 'dateAll' }, { name: 'weightAll'}])
            )
    });

    return new Ext.grid.GridPanel({
        anchor: '100%',
        layout: 'fit',
        enableHdMenu: false,
        autoScroll: true,
        containerScroll: true,
        autoHeight: true,
        //title: '报警列表',
        loadMask: { msg: '正在加载数据，请稍侯……' },
        //el: 'grid',
        store: dunCountInfoList,
        cm: cm,
        //bbar: bbar,
        bodyStyle: 'height:100%',
        viewConfig: {
            forceFit: true
        }
    });

}

function initTYPELJ() {

    //var carState = [["全部", "全部"], ["在线", "在线"], ["离线", "离线"]];厨余垃圾处理厂/其他垃圾处理厂/有害垃圾处理厂
//    厨余垃圾中转站 / 其他垃圾中转站 / 有害垃圾中转站 / 
//    厨余垃圾处理厂 / 其他垃圾处理厂 / 有害垃圾处理厂
    var carState = [["", "全部"], ["厨余垃圾中转站", "厨余垃圾中转站"], ["其他垃圾中转站", "其他垃圾中转站"], ["有害垃圾中转站", "有害垃圾中转站"]];
    var proxy = new Ext.data.MemoryProxy(carState);
    var Type_Car = Ext.data.Record.create([{ name: "cid", type: "string", mapping: 0 }, { name: "cname", type: "string", mapping: 1}]);
    var reader = new Ext.data.ArrayReader({}, Type_Car);
    var store = new Ext.data.Store({
        proxy: proxy,
        reader: reader//,
        //autoLoad:true
    });
    store.load();
    //定义一个下拉框
    var cmbCarState = new Ext.form.ComboBox({
        id: 'cmbTypeLJ',
        width: 180,
        allowBlank: false,
        triggerAction: "all", //是否开启自动查询功能
        store: store, //定义数据源
        displayField: "cname", //关联某一个逻辑列名作为显示值
        valueField: "cid", //关联某一个逻辑列名作为实际值
        mode: "local", //如果数据来自本地用local 如果来自远程用remote默认为remote
        emptyText: "请选择状态"//没有选择时候的默认值

    });
    Ext.getCmp("cmbTypeLJ").setValue("");
    return cmbCarState;
}

